package cn.lanqiao.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class JdbcUtil {
	private static final ComboPooledDataSource COMPOOL;
	static {
		COMPOOL = new ComboPooledDataSource();
	}
	public static void close(ResultSet rs,Statement ps,Connection con) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (con != null) {
				con.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static Connection getConnection() {
		Connection con = null;
		try {
			con = COMPOOL.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	//取出所有数据
//	public static void getAll() throws Exception{
//		Connection con = JdbcUtil.getConnection();
//		String insertSql="insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values(?,?,?,?,?,?,?,?)";
//		String updateSql = "update emp set ename = ?,job = ?,mgr = ?,hiredate = ?,sal = ?,comm = ?,deptno = ? where empno = ?";
//		String deleteSql = "delete from emp where empno = ?";
//		PreparedStatement ps = con.prepareStatement(insertSql);
//		ps.setInt(1, 112);
//		ps.setString(2, "小谭");
//		ps.setString(3, "JAVA");
//		ps.setInt(4, 7369);
//		java.util.Date utilDate = new java.util.Date();// 创建一个日期
//		java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
//		ps.setDate(5, sqlDate);
//		ps.setDouble(6, 5300);
//		ps.setDouble(7, 1000);
//		ps.setInt(8, 30);
//		int affter = ps.executeUpdate();
//		if (affter > 0) {
//			System.out.println("添加成功");
//		}else {
//			System.out.println("添加失败");
//		}
//	}
}